using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using SiteECSWeb;


public partial class UControls_Search : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(TableSubject))
        {
            BindContent(TableSubject);
        }
        if (!string.IsNullOrEmpty(TagCloudSelectMethod))
        {
            TagDataSource.SelectMethod = TagCloudSelectMethod;
            Cloud1.DataBind();
        }
       
    }
    #region OverrideControlMethods
    protected override void OnInit(EventArgs e)
    {
        Page.RegisterRequiresControlState(this);
        base.OnInit(e);
    }
    protected override void LoadControlState(object savedState)
    {
        object[] ctlState = (object[])savedState;
        base.LoadControlState(ctlState[0]);
        _tagCloudSelectMethod = ctlState[1].ToString();
        _dataSourceTypeName = ctlState[2].ToString();
        _dataSourceSelectMehtod = ctlState[3].ToString();
        _dataSourcSelectCountMethod = ctlState[4].ToString();
        _dataSourceSortParameterName = ctlState[5].ToString();
        _autoCompleteServiceMethod = ctlState[6].ToString();
        _tableSubject = ctlState[7].ToString();
        _visibleCountry = (bool)ctlState[8];
        _visibleProducts = (bool)ctlState[9];

    }
    protected override object SaveControlState()
    {
        object[] ctlState = new object[10];
        ctlState[0] = base.SaveControlState();
        ctlState[1] = _tagCloudSelectMethod;
        ctlState[2] = _dataSourceTypeName;
        ctlState[3] = _dataSourceSelectMehtod;
        ctlState[4] = _dataSourcSelectCountMethod;
        ctlState[5] = _dataSourceSortParameterName;
        ctlState[6] = _autoCompleteServiceMethod;
        ctlState[7] = _tableSubject;
        ctlState[8] = _visibleCountry;
        ctlState[9] = _visibleProducts;
        return ctlState;
    }
    #endregion

    #region Props

    private string _tagCloudSelectMethod;

    public string TagCloudSelectMethod
    {
        get
        {
            _tagCloudSelectMethod = ViewState["TagCloudSelectMethod"] as string;

            if (_tagCloudSelectMethod != null)
            {
                return _tagCloudSelectMethod;
            }

            return String.Empty;
        }
        set
        {
            ViewState["TagCloudSelectMethod"] = value;
        }
       //get { return _tagCloudSelectMethod; }
       //set { _tagCloudSelectMethod = value; }
    }
    private string _dataSourceTypeName;

    public string DataSourceTypeName
    {
        get
        {
            _dataSourceTypeName = ViewState["DataSourceTypeName"] as string;

            if (_dataSourceTypeName != null)
            {
                return _dataSourceTypeName;
            }

            return String.Empty;
        }
        set
        {
            ViewState["DataSourceTypeName"] = value;
        }
        //get { return _dataSourceTypeName; }
        //set { _dataSourceTypeName = value; }
    }

    private string _dataSourceSelectMehtod;

    public string DataSourceSelectMethod
    {
        get
        {
            _dataSourceSelectMehtod = ViewState["DataSourceSelectMethod"] as string;

            if (_dataSourceSelectMehtod != null)
            {
                return _dataSourceSelectMehtod;
            }

            return String.Empty;
        }
        set
        {
            ViewState["DataSourceSelectMethod"] = value;
        }
        //get { return _dataSourceSelectMehtod; }
        //set { _dataSourceSelectMehtod = value; }
    }

    private string _dataSourcSelectCountMethod;

    public string DataSourceSelectCountMethod
    {
        //get
        //{
        //    _dataSourcSelectCountMethod = ViewState["DataSourceSelectCountMethod"] as string;

        //    if (_dataSourcSelectCountMethod != null)
        //    {
        //        return _dataSourcSelectCountMethod;
        //    }

        //    return String.Empty;
        //}
        //set
        //{
        //    ViewState["DataSourceSelectCountMethod"] = value;
        //}
        get { return _dataSourcSelectCountMethod; }
        set { _dataSourcSelectCountMethod = value; }
    }
    private string _dataSourceSortParameterName;

    public string DataSourceSortParameterName
    {
        get
        {
            _dataSourceSortParameterName = ViewState["DataSourceSortParameterName"] as string;

            if (_dataSourceSortParameterName != null)
            {
                return _dataSourceSortParameterName;
            }

            return String.Empty;
        }
        set
        {
            ViewState["DataSourceSortParameterName"] = value;
        }
        //get { return _dataSourceSortParameterName; }
        //set { _dataSourceSortParameterName = value; }
    }

    private string _headerTitle;

    public string HeaderTitle
    {
        get
        {
            _headerTitle = ViewState["HeaderTitle"] as string;

            if (_headerTitle != null)
            {
                return _headerTitle;
            }

            return String.Empty;
        }
        set
        {
            ViewState["HeaderTitle"] = value;
        }
        //get { return _headerTitle; }
        //set { _headerTitle = value; }
    }
    private string _autoCompleteServiceMethod;

    public string AutoCompleteServiceMethod
    {
        get
        {
            _autoCompleteServiceMethod = ViewState["AutoCompleteServiceMethod"] as string;

            if (_autoCompleteServiceMethod != null)
            {
                return _autoCompleteServiceMethod;
            }

            return String.Empty;
        }
        set
        {
            ViewState["AutoCompleteServiceMethod"] = value;
        }
        //get { return _autoCompleteServiceMethod; }
        //set { _autoCompleteServiceMethod = value; }
    }
    private string _tableSubject;

    public string TableSubject
    {
        get
        {
            _tableSubject = ViewState["TableSubject"] as string;

            if (_tableSubject != null)
            {
                return _tableSubject;
            }

            return String.Empty;
        }
        set
        {
            ViewState["TableSubject"] = value;
        }
        //get { return _tableSubject; }
        //set { _tableSubject = value; }
    }

    private bool _visibleCountry;

    public bool VisibleCountry
    {
        get
        {
            _visibleCountry = (bool)ViewState["VisibleCountry"];

            return _visibleCountry;
        }
        set
        {
            ViewState["VisibleCountry"] = value;
        }
        
        //get { return _visibleCountry; }
        //set { _visibleCountry = value; }
    }

    private bool _visibleProducts;

    public bool VisibleProducts
    {
        get
        {
            _visibleProducts = (bool)ViewState["VisibleProducts"];
            //if (_visibleProducts != null)
            //{
            //    return _visibleProducts;
            //}
            return _visibleProducts;
        }
        set
        {
            ViewState["VisibleProducts"] = value;
        }
        //get { return _visibleProducts; }
        //set { _visibleProducts = value; }
    }
    private bool _visibleFairsType;

    public bool VisibleFairsType
    {
        get
        {
            _visibleFairsType = (bool)ViewState["VisibleFairsType"];
            //if (_visibleProducts != null)
            //{
            //    return _visibleProducts;
            //}
            return _visibleFairsType;
        }
        set
        {
            ViewState["VisibleFairsType"] = value;
        }
        //get { return _visibleProducts; }
        //set { _visibleProducts = value; }
    }

    public bool pnlContent
    {
        get 
        {
            return pnlgvContent.Visible;
            //return _restGridView; 
        }
        set 
        {
            pnlgvContent.Visible = value; 
        }
    }
	 
    #endregion

    #region FilterDataAll
    private string expressionText = null;

    protected void FilterData(string countrycolName, string productGrandcolName,
        string productFathercolName, string tablecolName, string sessionString)
    {
        StringBuilder sbCode = new StringBuilder();
        StringBuilder sbText = new StringBuilder();
        string expression = null;


        if (!string.IsNullOrEmpty(cddlCountryName.dllListItemsValue) ||
            !string.IsNullOrEmpty(cddlProductFather.dllListItemsValue) ||
            !string.IsNullOrEmpty(cddlProductGrand.dllListItemsValue) ||
            !string.IsNullOrEmpty(txtName.Text))
        {

            if (!string.IsNullOrEmpty(cddlCountryName.dllListItemsValue))
            {
                sbCode.Append(countrycolName + " ='" + cddlCountryName.dllListItemsValue.Trim() + "' AND ");
                sbText.Append(cddlCountryName.dllListItemsText.Trim() + " , ");
            }
            if (!string.IsNullOrEmpty(cddlProductGrand.dllListItemsValue))
            {
                sbCode.Append(productGrandcolName + " = " + cddlProductGrand.dllListItemsValue + " AND ");
                sbText.Append(cddlProductGrand.dllListItemsText.Trim() + " , ");
            }

            if (!string.IsNullOrEmpty(cddlProductFather.dllListItemsValue))
            {
                sbCode.Append(productFathercolName + " = " + cddlProductFather.dllListItemsValue + " AND ");
                sbText.Append(cddlProductFather.dllListItemsText.Trim() + " , ");
            }

            if (!string.IsNullOrEmpty(txtName.Text))
            {
                sbCode.Append(tablecolName + " LIKE '%" + txtName.Text.Trim() + "%' AND ");
                sbText.Append(txtName.Text.Trim() + " , ");
            }

            if (sbCode.ToString().EndsWith(" AND "))
            {
                expression = sbCode.ToString().Substring(0, sbCode.Length - 5);
            }
            if (sbText.ToString().EndsWith(" , "))
            {
                expressionText = sbText.ToString().Substring(0, sbText.Length - 3);
            }
            Session[sessionString] = expression;
        }
        else
        {
            Session[sessionString] = null;
            expressionText = null;
        }
    }
    protected void FilterFairsData(string countrycolName, string fairsTypecolName,
      string tablecolName, string sessionString)
    {
        StringBuilder sbCode = new StringBuilder();
        StringBuilder sbText = new StringBuilder();
        string expression = null;


        if (!string.IsNullOrEmpty(cddlCountryName.dllListItemsValue) ||
            !string.IsNullOrEmpty(ddlFairsType.SelectedItem.Value) ||
            !string.IsNullOrEmpty(txtName.Text))
        {

            if (!string.IsNullOrEmpty(cddlCountryName.dllListItemsValue))
            {
                sbCode.Append(countrycolName + " ='" + cddlCountryName.dllListItemsValue.Trim() + "' AND ");
                sbText.Append(cddlCountryName.dllListItemsText.Trim() + " , ");
            }
            if (!string.IsNullOrEmpty(ddlFairsType.SelectedItem.Value))
            {
                sbCode.Append(fairsTypecolName + " LIKE '%" + ddlFairsType.SelectedItem.Value.Trim() + "%' AND ");
                //LIKE '%" + ddlFairsType.SelectedValue.Trim() + "%'
                sbText.Append(ddlFairsType.SelectedItem.Value.Trim() + " , ");
            }

            if (!string.IsNullOrEmpty(txtName.Text))
            {
                sbCode.Append(tablecolName + " like '" + txtName.Text.Trim() + "%' AND ");
                sbText.Append(txtName.Text.Trim() + " , ");
            }

            if (sbCode.ToString().EndsWith(" AND "))
            {
                expression = sbCode.ToString().Substring(0, sbCode.Length - 5);
            }
            if (sbText.ToString().EndsWith(" , "))
            {
                expressionText = sbText.ToString().Substring(0, sbText.Length - 3);
            }
            Session[sessionString] = expression;
        }
        else
        {
            Session[sessionString] = null;
            expressionText = null;
        }
    }

    #endregion

  
    protected void SearchButton_Click(object sender, EventArgs e)
    {
        GridViewCus1.PageIndex = 0;
        pnlgvContent.Visible = true;
        if (!string.IsNullOrEmpty(TableSubject))
        {
            BindContent(TableSubject);
        }
    }
    
    protected void BindContent(string subject)
    {
        if (!string.IsNullOrEmpty(subject))
        {
            switch (subject.Trim())
            {
                case "ExportOpportunity":
                    BindExOpp();
                    break;
                case "Tenders":
                    BindTender();
                    break;
                case "News":
                    BindNews();
                    break;
                case "MStudy":
                    BindMStudy();
                    break;
                case "Fairs":
                    BindFairs();
                    break;
                case "ExporterGuide":
                    BindExpGuide();
                    break;
                case "Wcompany":
                    BindWcompany();
                    break;
                default:
                    break;
            }
        }
    }

    #region ExOpp
    protected void BindExOpp()
    {
        ltlHeader.Text = HeaderTitle;
        TagDataSource.SelectMethod = TagCloudSelectMethod;
        AutoCompleteExtender1.ServiceMethod = AutoCompleteServiceMethod;
        pnlCountry.Visible = VisibleCountry;
        pnlProducts.Visible = VisibleProducts;
        pnlFairsType.Visible = VisibleFairsType;
        CustomDataSource.TypeName = DataSourceTypeName;
        CustomDataSource.SelectMethod = DataSourceSelectMethod;
        CustomDataSource.SelectCountMethod = DataSourceSelectCountMethod;
        CustomDataSource.SortParameterName = DataSourceSortParameterName;
        GridViewCus1.DataKeyNames = new string[] { "Ex_oprtid" };
        FilterData("Country.Cuntry_un2", "ProductCategory.ProdCat_GropID",
            "ExpOpprtinty.ProdCat_Id", "ExpOpprtinty.Ex_oppNameAr", "filterSearchString");
        GridViewCus1.RowDataBound += new GridViewRowEventHandler(gvcExOpp_RowDataBound);        
        CustomDataSource.Selected += new ObjectDataSourceStatusEventHandler(cdsExOpp_Selected);
    }
    void gvcExOpp_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            EcsSiteDS.ExpOpprtintyRow expOpprow = (EcsSiteDS.ExpOpprtintyRow)
            ((System.Data.DataRowView)e.Row.DataItem).Row;
            HyperLink hylink = e.Row.FindControl("hylink") as HyperLink;
            Literal ltldate = e.Row.FindControl("ltldate") as Literal;
            Literal ltlDesc = e.Row.FindControl("ltlDesc") as Literal;
            Literal ltlCountry = e.Row.FindControl("ltlCountry") as Literal;
            Literal ltlCity = e.Row.FindControl("ltlCity") as Literal;
            Literal ltlCompany = e.Row.FindControl("ltlCompany") as Literal;

            hylink.Text = expOpprow.Ex_oppNameAr;
            hylink.NavigateUrl = Helper.
                NavURLParamsIntVirtualName(expOpprow.Ex_oprtid, Globals.Settings.VirtualNamesInfo.ExportOppDetails);
            ltldate.Text = expOpprow.Ex_oprtdate.ToString("dd/MM/yyyy");
            ltlDesc.Text = ((expOpprow.Ex_oprtspecif.Length > 25) ? expOpprow.Ex_oprtspecif.Substring(0, 25) :
                expOpprow.Ex_oprtspecif)
                + "....." +
                ((!expOpprow.IsEx_oprtofficomentNull()) ? 
                (((expOpprow.Ex_oprtofficoment.Length > 25) ? expOpprow.Ex_oprtofficoment.Substring(0, 25) :
                expOpprow.Ex_oprtofficoment)) : string.Empty)
                + ".....";

            ltlCountry.Text = expOpprow.CountryNmAr;
            ltlCity.Text = expOpprow.CityNmAr;
            ltlCompany.Text = expOpprow.CountryNmAr;
        }
    }
    void cdsExOpp_Selected(object sender, ObjectDataSourceStatusEventArgs e)
    {
        if (e.Exception == null)
        {
            ExpOppBLL ExprtOppAPI = new ExpOppBLL();
            if (Session["filterSearchString"] == null)
            {
                int rows = ExprtOppAPI.GetTotalNumberOfExportOpp(string.Empty);
                lbResult.Text = Helper.PagerLocation(GridViewCus1.PageIndex,
                    GridViewCus1.PageSize, rows, expressionText);
            }
            else
            {
                int rows = ExprtOppAPI.GetTotalNumberOfExportOpp(Session["filterSearchString"].ToString());
                lbResult.Text = Helper.PagerLocation(GridViewCus1.PageIndex,
                    GridViewCus1.PageSize, rows, expressionText);
            }
        }
    }
    #endregion

    #region Tenders
    protected void BindTender()
    {
        ltlHeader.Text = HeaderTitle;

        TagDataSource.SelectMethod = TagCloudSelectMethod;
        AutoCompleteExtender1.ServiceMethod = AutoCompleteServiceMethod;
        pnlCountry.Visible = VisibleCountry;
        pnlProducts.Visible = VisibleProducts;
        pnlFairsType.Visible = VisibleFairsType;
        CustomDataSource.TypeName = DataSourceTypeName;
        CustomDataSource.SelectMethod = DataSourceSelectMethod;
        CustomDataSource.SelectCountMethod = DataSourceSelectCountMethod;
        CustomDataSource.SortParameterName = DataSourceSortParameterName;
        GridViewCus1.DataKeyNames = new string[] { "Tend_id" };
        FilterData("cnty.Cuntry_un2", "pcat.ProdCat_GropID",
            "tenders.ProdCat_Id", "Tenders.Tend_name", "filterSearchString");
        GridViewCus1.RowDataBound += new GridViewRowEventHandler(gvcTender_RowDataBound);
        //GridViewCus1.PageIndexChanging += new GridViewPageEventHandler(gvcExOpp_PageIndexChanging);
        CustomDataSource.Selected += new ObjectDataSourceStatusEventHandler(cdsTender_Selected);
        //GridViewCus1.DataBind();
        //Cloud1.DataBind();
    }
    void gvcTender_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            EcsSiteDS.TendersRow tenderrow = (EcsSiteDS.TendersRow)
            ((System.Data.DataRowView)e.Row.DataItem).Row;
            HyperLink hylink = e.Row.FindControl("hylink") as HyperLink;
            Literal ltldate = e.Row.FindControl("ltldate") as Literal;
            Literal ltlDesc = e.Row.FindControl("ltlDesc") as Literal;
            Literal ltlCountry = e.Row.FindControl("ltlCountry") as Literal;
            Literal ltlCity = e.Row.FindControl("ltlCity") as Literal;
            Literal ltlCompany = e.Row.FindControl("ltlCompany") as Literal;

            hylink.Text = tenderrow.Tend_name;
            hylink.NavigateUrl = Helper.
                NavURLParamsIntVirtualName(tenderrow.Tend_id, Globals.Settings.VirtualNamesInfo.TendersDetails);
            ltldate.Text = tenderrow.Tend_stdate.ToString("dd/MM/yyyy");
            ltlDesc.Text = ((tenderrow.Tend_specif.Length > 25) ? tenderrow.Tend_specif.Substring(0, 25) :
                tenderrow.Tend_specif);
            //+ "....." +
            //((tenderrow.Tend_registerBook.Length > 25) ? tenderrow.Tend_registerBook.Substring(0, 25) :
            //tenderrow.Tend_registerBook)
            //+ ".....";

            ltlCountry.Text = tenderrow.CountryNmAr;
            ltlCity.Text = tenderrow.CityNmAr;
            ltlCompany.Text = (tenderrow.IsWCompNmEnNull() ? string.Empty : tenderrow.WCompNmEn);
        }
    }

    void cdsTender_Selected(object sender, ObjectDataSourceStatusEventArgs e)
    {
        if (e.Exception == null)
        {
            TenderBLL TenderAPI = new TenderBLL();
            if (Session["filterSearchString"] == null)
            {
                int rows = TenderAPI.GetTotalNumberOfTenders(string.Empty);
                lbResult.Text = Helper.PagerLocation(GridViewCus1.PageIndex,
                    GridViewCus1.PageSize, rows, expressionText);
            }
            else
            {
                int rows = TenderAPI.GetTotalNumberOfTenders(Session["filterSearchString"].ToString());
                lbResult.Text = Helper.PagerLocation(GridViewCus1.PageIndex,
                    GridViewCus1.PageSize, rows, expressionText);
            }
        }
    }
  
    #endregion

    #region MStudies
    protected void BindMStudy()
    {
        ltlHeader.Text = HeaderTitle;

        TagDataSource.SelectMethod = TagCloudSelectMethod;
        AutoCompleteExtender1.ServiceMethod = AutoCompleteServiceMethod;
        pnlCountry.Visible = VisibleCountry;
        pnlProducts.Visible = VisibleProducts;
        pnlFairsType.Visible = VisibleFairsType;
        CustomDataSource.TypeName = DataSourceTypeName;
        CustomDataSource.SelectMethod = DataSourceSelectMethod;
        CustomDataSource.SelectCountMethod = DataSourceSelectCountMethod;
        CustomDataSource.SortParameterName = DataSourceSortParameterName;
        GridViewCus1.DataKeyNames = new string[] { "Mstdy_id" };
        FilterData("Country.Cuntry_un2", "pcat.ProdCat_GropID",
            "pcat.ProdCat_Id", "MStudy.Mstdy_name", "filterSearchString");
        GridViewCus1.RowDataBound += new GridViewRowEventHandler(gvcMStudy_RowDataBound);
        //GridViewCus1.PageIndexChanging += new GridViewPageEventHandler(gvcExOpp_PageIndexChanging);
        CustomDataSource.Selected += new ObjectDataSourceStatusEventHandler(cdsMStudy_Selected);
        //GridViewCus1.DataBind();
        //Cloud1.DataBind();
    }

    void gvcMStudy_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            EcsSiteDS.MStudyRow mstudyrow = (EcsSiteDS.MStudyRow)
            ((System.Data.DataRowView)e.Row.DataItem).Row;
            HyperLink hylink = e.Row.FindControl("hylink") as HyperLink;
            Literal ltldate = e.Row.FindControl("ltldate") as Literal;
            Literal ltlDesc = e.Row.FindControl("ltlDesc") as Literal;
            Literal ltlCountry = e.Row.FindControl("ltlCountry") as Literal;
            Literal ltlCity = e.Row.FindControl("ltlCity") as Literal;
            Literal ltlCompany = e.Row.FindControl("ltlCompany") as Literal;

            hylink.Text = mstudyrow.Mstdy_name;
            hylink.NavigateUrl = Helper.
                NavURLParamsIntVirtualName(mstudyrow.Mstdy_id, Globals.Settings.VirtualNamesInfo.MStudyDetails);
            ltldate.Text = mstudyrow.Mstdy_date.ToString("dd/MM/yyyy");
            ltlDesc.Text = ((mstudyrow.Mstdy_memo.Length > 25) ? mstudyrow.Mstdy_memo.Substring(0, 25) :
                mstudyrow.Mstdy_memo)
                + ".....";
            //((expOpprow.Ex_oprtofficoment.Length > 25) ? expOpprow.Ex_oprtofficoment.Substring(0, 25) :
            //expOpprow.Ex_oprtofficoment)
            //+ ".....";

            ltlCountry.Text = mstudyrow.CountryNmAr;
            ltlCity.Text = mstudyrow.CityNmAr;
            //ltlCompany.Text = mstudyrow.auth;
        }
    }
    void cdsMStudy_Selected(object sender, ObjectDataSourceStatusEventArgs e)
    {
        if (e.Exception == null)
        {
            MStudyBLL MStudyAPI = new MStudyBLL();
            if (Session["filterSearchString"] == null)
            {
                int rows = MStudyAPI.GetTotalNumberOfMStudies(string.Empty);
                lbResult.Text = Helper.PagerLocation(GridViewCus1.PageIndex,
                    GridViewCus1.PageSize, rows, expressionText);
            }
            else
            {
                int rows = MStudyAPI.GetTotalNumberOfMStudies(Session["filterSearchString"].ToString());
                lbResult.Text = Helper.PagerLocation(GridViewCus1.PageIndex,
                    GridViewCus1.PageSize, rows, expressionText);
            }
        }
    }
    #endregion

    #region News
    protected void BindNews()
    {
        ltlHeader.Text = HeaderTitle;

        TagDataSource.SelectMethod = TagCloudSelectMethod;
        AutoCompleteExtender1.ServiceMethod = AutoCompleteServiceMethod;
        pnlCountry.Visible = VisibleCountry;
        pnlProducts.Visible = VisibleProducts;
        pnlFairsType.Visible = VisibleFairsType;
        CustomDataSource.TypeName = DataSourceTypeName;
        CustomDataSource.SelectMethod = DataSourceSelectMethod;
        CustomDataSource.SelectCountMethod = DataSourceSelectCountMethod;
        CustomDataSource.SortParameterName = DataSourceSortParameterName;
        GridViewCus1.DataKeyNames = new string[] { "News_id" };
        FilterData("cnty.Cuntry_un2", string.Empty,
            string.Empty, "News.News_nm", "filterSearchString");
        GridViewCus1.RowDataBound += new GridViewRowEventHandler(gvcNews_RowDataBound);
        //GridViewCus1.PageIndexChanging += new GridViewPageEventHandler(gvcExOpp_PageIndexChanging);
        CustomDataSource.Selected += new ObjectDataSourceStatusEventHandler(cdsNews_Selected);
        //GridViewCus1.DataBind();
        //Cloud1.DataBind();
    }
   
 
    void gvcNews_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            EcsSiteDS.NewsRow newsrow = (EcsSiteDS.NewsRow)
            ((System.Data.DataRowView)e.Row.DataItem).Row;
            HyperLink hylink = e.Row.FindControl("hylink") as HyperLink;
            Literal ltldate = e.Row.FindControl("ltldate") as Literal;
            Literal ltlDesc = e.Row.FindControl("ltlDesc") as Literal;
            Literal ltlCountry = e.Row.FindControl("ltlCountry") as Literal;
            Literal ltlCity = e.Row.FindControl("ltlCity") as Literal;
            Literal ltlCompany = e.Row.FindControl("ltlCompany") as Literal;

            hylink.Text = newsrow.News_nm;
            hylink.NavigateUrl = Helper.
                NavURLParamsIntVirtualName(newsrow.News_id, Globals.Settings.VirtualNamesInfo.NewsDetails);
            ltldate.Text = newsrow.News_date.ToString("dd/MM/yyyy");
            ltlDesc.Text = ((newsrow.News_descr.Length > 25) ? newsrow.News_descr.Substring(0, 25) :
                newsrow.News_descr);
            //+ "....." +
            //((tenderrow.Tend_registerBook.Length > 25) ? tenderrow.Tend_registerBook.Substring(0, 25) :
            //tenderrow.Tend_registerBook)
            //+ ".....";
            ltlCountry.Text = newsrow.CountryNmAr;            
            
        }
    }
  
  
  
    void cdsNews_Selected(object sender, ObjectDataSourceStatusEventArgs e)
    {
        if (e.Exception == null)
        {
            NewsBLL NewsAPI = new NewsBLL();
            if (Session["filterSearchString"] == null)
            {
                int rows = NewsAPI.GetTotalNumberOfNews(string.Empty);
                lbResult.Text = Helper.PagerLocation(GridViewCus1.PageIndex,
                    GridViewCus1.PageSize, rows, expressionText);
            }
            else
            {
                int rows = NewsAPI.GetTotalNumberOfNews(Session["filterSearchString"].ToString());
                lbResult.Text = Helper.PagerLocation(GridViewCus1.PageIndex,
                    GridViewCus1.PageSize, rows, expressionText);
            }
        }
    }
    #endregion

    #region Fairs
    protected void BindFairs()
    {
        ltlHeader.Text = HeaderTitle;

        TagDataSource.SelectMethod = TagCloudSelectMethod;
        AutoCompleteExtender1.ServiceMethod = AutoCompleteServiceMethod;
        pnlCountry.Visible = VisibleCountry;
        pnlProducts.Visible = VisibleProducts;
        pnlFairsType.Visible = VisibleFairsType;

        CustomDataSource.TypeName = DataSourceTypeName;
        CustomDataSource.SelectMethod = DataSourceSelectMethod;
        CustomDataSource.SelectCountMethod = DataSourceSelectCountMethod;
        CustomDataSource.SortParameterName = DataSourceSortParameterName;

        GridViewCus1.DataKeyNames = new string[] { "Fair_id" };
        FilterFairsData("Country.Cuntry_un2", "Fairs.Fair_Type",
            "Fairs.Fair_nm", "filterSearchString");
        GridViewCus1.RowDataBound += new GridViewRowEventHandler(gvcFairs_RowDataBound);        
        CustomDataSource.Selected += new ObjectDataSourceStatusEventHandler(cdsFairs_Selected);
    }

    void gvcFairs_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            EcsSiteDS.FairsRow Fairsrow = (EcsSiteDS.FairsRow)
            ((System.Data.DataRowView)e.Row.DataItem).Row;
            HyperLink hylink = e.Row.FindControl("hylink") as HyperLink;
            Literal ltldate = e.Row.FindControl("ltldate") as Literal;
            Literal ltlDesc = e.Row.FindControl("ltlDesc") as Literal;
            Literal ltlCountry = e.Row.FindControl("ltlCountry") as Literal;
            Literal ltlCity = e.Row.FindControl("ltlCity") as Literal;
            Literal ltlCompany = e.Row.FindControl("ltlCompany") as Literal;

            hylink.Text = Fairsrow.Fair_nm;
            hylink.NavigateUrl = Helper.
                NavURLParamsIntVirtualName(Fairsrow.Fair_id, Globals.Settings.VirtualNamesInfo.FairsDetails);
            ltldate.Text = Fairsrow.Fair_strtdate.ToString("dd/MM/yyyy");
            ltlDesc.Text = ((Fairsrow.Fair_desc.Length > 25) ? Fairsrow.Fair_desc.Substring(0, 25) :
                Fairsrow.Fair_desc)
                + ".....";

            ltlCountry.Text = Fairsrow.CountryNmAr;
            ltlCity.Text = Fairsrow.CityNmAr;            
        }
    }
    void cdsFairs_Selected(object sender, ObjectDataSourceStatusEventArgs e)
    {
        if (e.Exception == null)
        {
            FairsBLL FairsAPI = new FairsBLL();
            if (Session["filterSearchString"] == null)
            {
                int rows = FairsAPI.GetTotalNumberOfFairs(string.Empty);
                lbResult.Text = Helper.PagerLocation(GridViewCus1.PageIndex,
                    GridViewCus1.PageSize, rows, expressionText);
            }
            else
            {
                int rows = FairsAPI.GetTotalNumberOfFairs(Session["filterSearchString"].ToString());
                lbResult.Text = Helper.PagerLocation(GridViewCus1.PageIndex,
                    GridViewCus1.PageSize, rows, expressionText);
            }
        }
    }
    #endregion

    #region ExpGuide
    protected void BindExpGuide()
    {
        ltlHeader.Text = HeaderTitle;

        TagDataSource.SelectMethod = TagCloudSelectMethod;
        AutoCompleteExtender1.ServiceMethod = AutoCompleteServiceMethod;
        pnlCountry.Visible = VisibleCountry;
        pnlProducts.Visible = VisibleProducts;
        pnlFairsType.Visible = VisibleFairsType;
        CustomDataSource.TypeName = DataSourceTypeName;
        CustomDataSource.SelectMethod = DataSourceSelectMethod;
        CustomDataSource.SelectCountMethod = DataSourceSelectCountMethod;
        CustomDataSource.SortParameterName = DataSourceSortParameterName;
        GridViewCus1.DataKeyNames = new string[] { "Exporterguid_id" };
        FilterData("Country.Cuntry_un2", string.Empty,
            string.Empty, "ExporterGuide.Exporterguid_nmar", "filterSearchString");
        GridViewCus1.RowDataBound += new GridViewRowEventHandler(gvcExpGuide_RowDataBound);
        //GridViewCus1.PageIndexChanging += new GridViewPageEventHandler(gvcExOpp_PageIndexChanging);
        CustomDataSource.Selected += new ObjectDataSourceStatusEventHandler(cdsExpGuide_Selected);
        //GridViewCus1.DataBind();
        //Cloud1.DataBind();
    }


    void gvcExpGuide_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            EcsSiteDS.ExporterGuideRow ExpGuiderow = (EcsSiteDS.ExporterGuideRow)
            ((System.Data.DataRowView)e.Row.DataItem).Row;
            HyperLink hylink = e.Row.FindControl("hylink") as HyperLink;
            Literal ltldate = e.Row.FindControl("ltldate") as Literal;
            Literal ltlDesc = e.Row.FindControl("ltlDesc") as Literal;
            Literal ltlCountry = e.Row.FindControl("ltlCountry") as Literal;
            Literal ltlCity = e.Row.FindControl("ltlCity") as Literal;
            Literal ltlCompany = e.Row.FindControl("ltlCompany") as Literal;

            hylink.Text = ExpGuiderow.Exporterguid_nmar;
            hylink.NavigateUrl = Helper.
                NavURLParamsIntVirtualName(ExpGuiderow.Exporterguid_id, Globals.Settings.VirtualNamesInfo.ExporterGuideDetails);
            ltldate.Text = ExpGuiderow.Exporterguid_Date.ToString("dd/MM/yyyy");
            ltlDesc.Text = ((ExpGuiderow.Exporterguid_memo.Length > 25) ? ExpGuiderow.Exporterguid_memo.Substring(0, 25) :
                ExpGuiderow.Exporterguid_memo);
            ltlCountry.Text = ExpGuiderow.CountryNmAr;
        }
    }



    void cdsExpGuide_Selected(object sender, ObjectDataSourceStatusEventArgs e)
    {
        if (e.Exception == null)
        {
            ExporterGuideBLL ExpGuideAPI = new ExporterGuideBLL();
            if (Session["filterSearchString"] == null)
            {
                int rows = ExpGuideAPI.GetTotalNumberOfExporterGuide(string.Empty);
                lbResult.Text = Helper.PagerLocation(GridViewCus1.PageIndex,
                    GridViewCus1.PageSize, rows, expressionText);
            }
            else
            {
                int rows = ExpGuideAPI.GetTotalNumberOfExporterGuide(Session["filterSearchString"].ToString());
                lbResult.Text = Helper.PagerLocation(GridViewCus1.PageIndex,
                    GridViewCus1.PageSize, rows, expressionText);
            }
        }
    }
    #endregion

    #region Wcompany
    protected void BindWcompany()
    {
        ltlHeader.Text = HeaderTitle;

        TagDataSource.SelectMethod = TagCloudSelectMethod;

        AutoCompleteExtender1.ServiceMethod = AutoCompleteServiceMethod;
        pnlCountry.Visible = VisibleCountry;
        pnlProducts.Visible = VisibleProducts;
        pnlFairsType.Visible = VisibleFairsType;
        CustomDataSource.TypeName = DataSourceTypeName;
        CustomDataSource.SelectMethod = DataSourceSelectMethod;
        CustomDataSource.SelectCountMethod = DataSourceSelectCountMethod;
        CustomDataSource.SortParameterName = DataSourceSortParameterName;
        GridViewCus1.DataKeyNames = new string[] { "Wcomp_id" };
        FilterData("Country.Cuntry_un2", "ProductCategory.ProdCat_GropID",
            "Wcompanys.ProdCat_Id", "Wcompany.Wcomp_fulnmen", "filterSearchString");
        GridViewCus1.RowDataBound += new GridViewRowEventHandler(gvcWcompany_RowDataBound);
        CustomDataSource.Selected += new ObjectDataSourceStatusEventHandler(cdsWcompany_Selected);

    }
    void gvcWcompany_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            EcsSiteDS.WcompanyRow Wcompanyrow = (EcsSiteDS.WcompanyRow)
            ((System.Data.DataRowView)e.Row.DataItem).Row;
            HyperLink hylink = e.Row.FindControl("hylink") as HyperLink;
            Literal ltldate = e.Row.FindControl("ltldate") as Literal;
            Literal ltlDesc = e.Row.FindControl("ltlDesc") as Literal;
            Literal ltlCountry = e.Row.FindControl("ltlCountry") as Literal;
            Literal ltlCity = e.Row.FindControl("ltlCity") as Literal;
            Literal ltlCompany = e.Row.FindControl("ltlCompany") as Literal;

            hylink.Text = Wcompanyrow.Wcomp_fulnmen;
            hylink.NavigateUrl = Helper.
                NavURLParamsIntVirtualName(Wcompanyrow.Wcomp_id, Globals.Settings.VirtualNamesInfo.WcompanyDetails);
            ltldate.Text = string.Empty;

            if (!Wcompanyrow.IsWcomp_descNull())
            {
                 ltlDesc.Text = ((Wcompanyrow.Wcomp_desc.Length > 25) ? Wcompanyrow.Wcomp_desc.Substring(0, 25) :
                     Wcompanyrow.Wcomp_desc);
            }
            ltlCountry.Text = Wcompanyrow.CountryNmAr;
            ltlCity.Text = Wcompanyrow.CityNmAr;
            ltlCompany.Text = string.Empty;
        }
    }

    void cdsWcompany_Selected(object sender, ObjectDataSourceStatusEventArgs e)
    {
        if (e.Exception == null)
        {
            WcompanyBLL WcompanyAPI = new WcompanyBLL();
            if (Session["filterSearchString"] == null)
            {
                int rows = WcompanyAPI.GetTotalNumberOfWcompany(string.Empty);
                lbResult.Text = Helper.PagerLocation(GridViewCus1.PageIndex,
                    GridViewCus1.PageSize, rows, expressionText);
            }
            else
            {
                int rows = WcompanyAPI.GetTotalNumberOfWcompany(Session["filterSearchString"].ToString());
                lbResult.Text = Helper.PagerLocation(GridViewCus1.PageIndex,
                    GridViewCus1.PageSize, rows, expressionText);
            }
        }
    }

    #endregion

}
